package ycl.common.base.service.impl;

import ycl.common.base.entity.BaseChannelEntity;
import ycl.common.base.mapper.BaseChannelMapper;
import ycl.common.base.service.BaseChannelService;
import ycl.common.models.req.BaseReq;
import ycl.common.models.res.BaseChannelEntityRes;
import ycl.common.utils.AnnotationUtil;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分类处理层
 *
 * @author YCL
 * @date 2021-08-23 20:42:57
 */
@Service
@Lazy
public abstract class BaseChannelServiceImpl
		<M extends BaseChannelMapper<T>,
				T extends BaseChannelEntity,
				Q extends BaseReq,
				R extends BaseChannelEntityRes>
		extends BaseServiceImpl<M, T, Q, R>
		implements BaseChannelService<T, Q, R> {

	@Resource
	protected BaseChannelMapper<T> mapper;

	/**
	 * 根据父id查询子节点
	 *
	 * @param c  分类实体类
	 * @param id 要查询的id
	 * @return 子节点的集合
	 */
	public List<T> selectByPid(Class<T> c, Long id) {
		String tableName = AnnotationUtil.getTableName(c);
		return mapper.selectByPid(tableName, id);
	}

	/**
	 * 根据子节点的id查询父节点id
	 *
	 * @param c  分类实体类
	 * @param id 要查询的id
	 * @return 父节点的id
	 */
	public T selectPidById(Class<T> c, Long id) {
		String tableName = AnnotationUtil.getTableName(c);
		return mapper.selectPidById(tableName, id);
	}
}
